﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;

namespace JM.JCY.SharePointComponent.PerformanceArchives.PerformanceBasicInfo
{
    public partial class PerformanceBasicInfoUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentAccount = SPContext.Current.Web.CurrentUser.Name;
            string listName = "工作任务完成情况";
            if (!IsPostBack)
            {
                SPWeb web = SPContext.Current.Web;
                SPList list = web.Lists[listName];
                this.lvListPerformance.ListId = list.ID.ToString();
                lvListPerformance.ViewId = list.Views["MyView"].ID.ToString();
                using (UserManagementProxy userProxy = new UserManagementProxy())
                {
                    int userId = 0;
                    DataSetUserManagement.T_UserInfoDataTable userDT = userProxy.GetUser(0, currentAccount);
                    if (userDT.Rows.Count > 0)
                        userId = userDT[0].ID;

                    DepartmentTitleDataSet.T_DeptTitleDataTable dt = userProxy.GetDeptTitleByUserId(userId);
                    foreach (DepartmentTitleDataSet.T_DeptTitleRow dr in dt.Rows)
                    {
                        if (dr.JobTitle.Contains("政治处主任") || dr.JobTitle.Contains("检察长"))
                        {
                            lvListPerformance.ViewId = list.Views["All"].ID.ToString();
                        }
                    }


                }

              

                string href = string.Format("/MyDept/_layouts/listform.aspx?PageType=8&ListId={0}&RootFolder=", list.ID);
                string onclick = string.Format("javascript:NewItem2(event, '{0}');javascript:return false;", href);
                this.idHomePageNewItem.Attributes.Add("onclick", onclick);
            }
        }
    }
}
